package com.movitech.mobile.cz.base.purchase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.common.util.DateUtils;
import com.movitech.mobile.cz.base.modules.config.AttachmentTypeEnum;
import com.movitech.mobile.cz.base.purchase.entity.WFlowFormInquiringBid;
import com.movitech.mobile.cz.base.purchase.entity.ext.ExtWFlowFormInquiringBid;
import com.movitech.mobile.cz.base.purchase.mapper.WFlowFormInquiringBidMapper;
import com.movitech.mobile.cz.base.purchase.mapper.ext.ExtWFlowFormInquiringBidMapper;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormInquiringBidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 流程表单-询标 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@Service
public class WFlowFormInquiringBidServiceImpl extends ServiceImpl<WFlowFormInquiringBidMapper, WFlowFormInquiringBid> implements WFlowFormInquiringBidService {
    @Autowired
    private ExtWFlowFormInquiringBidMapper extWFlowFormInquiringBidMapper;
    @Override
    public List<ExtWFlowFormInquiringBid> getExtByFormId(String formId) {
        Map<String,Object> map = Maps.newHashMap();
        map.put("formId",formId);
        map.put("askType", AttachmentTypeEnum.ATTACHMENT_TYPE_27.getCode());
        map.put("answerType", AttachmentTypeEnum.ATTACHMENT_TYPE_28.getCode());
        return extWFlowFormInquiringBidMapper.getByFormId(map);
    }

    @Override
    public List<ExtWFlowFormInquiringBid> getExtByFormIdAndSupplierId(String formId,String supplierId) {
        Map<String,Object> map = Maps.newHashMap();
        map.put("formId",formId);
        map.put("askType", AttachmentTypeEnum.ATTACHMENT_TYPE_27.getCode());
        map.put("answerType", AttachmentTypeEnum.ATTACHMENT_TYPE_28.getCode());
        map.put("supplierId", supplierId);
        return extWFlowFormInquiringBidMapper.getByFormIdAndSupplierId(map);
    }

    @Override
    public boolean deleteById(String id) {
        WFlowFormInquiringBid wFlowFormInquiringBid = new WFlowFormInquiringBid();
        wFlowFormInquiringBid.setId(id);
        wFlowFormInquiringBid.setDelFlag(CommonConstants.DEL_FLAG_DELETE);
        return updateById(wFlowFormInquiringBid);
    }

    @Override
    public Date setReadById(String id) {
        Date now = DateUtils.getNow();
        WFlowFormInquiringBid wFlowFormInquiringBid = new WFlowFormInquiringBid();
        wFlowFormInquiringBid.setReadOrNot(CommonConstants.YES_INTEGER);
        wFlowFormInquiringBid.setDownloadTime(DateUtils.getNow());
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq("id",id).eq("read_or_not",CommonConstants.NO_INTEGER);
        if(!update(wFlowFormInquiringBid,entityWrapper))
            now = null;
        return now;
    }

}
